import request from "utils/request";
import { deepClone } from "utils";
import {StringData} from "utils";

//定义接口地址
const URL = {
  REF_PORTAL_SEARCH: `/uitemplate_web/iref_ctr/commonRefsearch`, //参照-查询列表
  //REF_PORTAL_SEARCH_SELECT: `/uitemplate_web/iref_ctr/filterRefJSON` //参照-快速查询
  REF_PORTAL_SEARCH_SELECT: `/uitemplate_web/iref_ctr/commonRefsearch` //参照-快速查询
};

/**
 * 参照列表获取
 * @param {*} params
 */
export const getRefList = param => {
  let newParam = Object.assign({}, param);
  let headers = { "Content-type": "application/x-www-form-urlencoded" };
  //let temp = 'condition=&content=&pk_val=&filterPks=&refModelUrl=%2Focc-base%2Fcurrency-ref%2F&pk_org=&transmitParam=&refName=%2525E5%2525B8%252581%2525E7%2525A7%25258D&refCode=&refModelClassName=&refModelHandlerClass=&cfgParam=%7B%22ctx%22%3A%22%2Fuitemplate_web%22%2C%22refCode%22%3A%22%22%7D&clientParam=%7B%22AUTH_refcod%22%3A%22customer%22%2C%22AUTH_refdim%22%3A%22currency%22%2C%22EQ_isEnable%22%3A%221%22%7D&refClientPageInfo.currPageIndex=0';
  return request(URL.REF_PORTAL_SEARCH, {
    method: "post",
    data: StringData(newParam.pageParams),
    ContentType: "application/x-www-form-urlencoded"
    })
};
/**
 * 参照--快捷查询select
 * @param {*} params
 */
export const getRefSelect = param => {
  let newParam = Object.assign({}, param);
  return request(URL.REF_PORTAL_SEARCH_SELECT, {
    method: "post",
    data: StringData(newParam.pageParams),
    ContentType: "application/x-www-form-urlencoded"
  });
};

/**
 * table获取参照列表
 * @param {*} params
 */
export const getRefTableList = param => {
  let newParam = Object.assign({}, param),
    pageParams = deepClone(newParam.pageParams);
  let URL = newParam.refUrl.tableUrl;
  delete newParam.pageParams;
  return request(URL, {
    method: "get",
    data: newParam,
    param: pageParams
  });
};

/**
 * tree获取参照列表
 * @param {*} params
 */
export const getRefTreeList = param => {
  let newParam = Object.assign({}, param),
    pageParams = deepClone(newParam.pageParams);
  let URL = newParam.refUrl.treeUrl;
  delete newParam.pageParams;
  return request(URL, {
    method: "get",
    data: newParam,
    param: pageParams
  });
};
